/*
 * Msg box - jQuery Plugin
 */
(function($){
    $.showMsg = function(message, options){
    
        settings = $.extend(true, {}, $.showMsg.defaults, options);
        
        var elem = $('#' + settings.id);
        var delayed;
        
        // generate message div if it doesn't exist
        if (elem.length == 0) {
            elem = $('<div></div>').attr('id', settings.id);
            
            $('<div>').addClass('msg-type').appendTo(elem);
            
            $('<div>').addClass('msg-text').appendTo(elem);
            
            $('body').append(elem);
        }
        
		elem.removeAttr('style');
        elem.css(settings.containerCss);
		
		var icon = elem.children('.msg-type');
		
		icon.removeAttr('style');
		icon.removeClass('info error warn quest');
		icon.css(settings.iconCss);
        
		var text = elem.children('.msg-text');
		text.removeAttr('style');
		text.css(settings.textCss).html(message);
		if(settings.width){
			text.css('width', settings.width+'px');
		}
		
		icon.addClass('info');
		
		if(settings.type){
			if(settings.type == 'error'){
				icon.addClass('error');
			}else if(settings.type == 'warn'){
				icon.addClass('warn');
			}else if(settings.type == 'quest'){
				icon.addClass('quest');
			}
		}
		
        var width = ($(window).width() - elem.outerWidth()) / 2;
        elem.css('left', width + 'px');
        
        elem.css('top', '-' + elem.outerHeight() + 'px');
        elem.animate({top: '0'}, settings.speed);
        delayed = '$("#' + settings.id + '").animate({top:"-' + elem.outerHeight() + 'px"}, ' + settings.speed + ');';
        setTimeout(delayed, settings.delay);
    };
	
    $.showMsg.defaults = {
        id: 'sliding_message_box',
        containerCss: {
            'z-index': '10008',
            'background-color': '#464646',
            'opacity': '0.8',
            'filter': 'alpha(opacity=80)',
            'position': 'absolute',
            'position': 'fixed',
            'left': '0',
            'font-size': '14px',
            'padding': '10px'
        },
        iconCss: {
            'float': 'left',
            'width': '24px',
            'height': '24px',
			'margin-right': '5px'
        },
        textCss: {
            'float': 'left',
            'line-height': '24px',
			'color': 'white',
			'font-family': 'arial'
        },
        delay: 1500,
        speed: 500
    };
    
    $.showError = function(msg){
    	$.showMsg(msg, {type:'error'});
    }
})(jQuery);
